var api = getApp(), WxParse = require('../../wxParse/wxParse.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        articleInfo: [],
        isPlay: 1,
        musicShow: !1,
        article_id: '',
        praise_count: '',
        isShowModel: !1,
        showPowerModal: !0,
        powerArr: [
            {
                id: 1,
                title: "公开",
                intro: "所有人可见，且录入个人专栏"
            }, {
                id: 0,
                title: "不公开",
                intro: "自行控制分享范围，仅被分享的人可见"
            }
        ],
        powerId: '',
        a_id: ''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (o) {
        var a = this;
        wx.showLoading({ title: '加载中...' });
        a.data.article_id = o.article_id;
        wx.request({
            url: api.globalData.Api + '/articleInfo',
            method: 'GET',
            dataType: 'json',
            data: {
                articleId: o.article_id,
                u_id: o.user_id
            },
            success(res) {
                let d = res.data.data;
                var e = wx.createInnerAudioContext();
                e.autoplay = true, e.loop = false, e.src = d.music_url;
                a.data.articleInfo = d, a.data.praise_count = d.good_count;
                a.data.powerId = d.authority, a.data.a_id = d.id;
                a.setData({
                    articleInfo: d,
                    innerAudioContext: e,
                    praise_count: d.good_count,
                    u_id: o.user_id,
                    powerId: a.data.powerId
                });
                WxParse.wxParse('article', 'html', d.content, a, 0), wx.hideLoading();
            }
        })
    },
    goEdit: function(){
        wx.navigateTo({
            url: "/pages/edit/edit?a_id=" + this.data.a_id + '&edArticle_wy=' + 1
        })
    },

    showMore: function (t) {
        this.setData({
            isShowMore: !0
        });
    },
    hideMore: function (t) {
        this.setData({
            isShowMore: !1
        });
    },

    showDelModal: function(){
        var a = this, a_id = a.data.a_id;
        a.setData({ isShowMore: !1 });
        wx.showModal({
            title: '删除',
            content: '确定要删除吗？删除后不可恢复哟！',
            success(res) {
                if (res.confirm) {
                    wx.request({
                        url: api.globalData.Api + '/articleDel',
                        method: 'GET',
                        data: { id: a_id },
                        success(res) {
                            if(res.data.status == 1){
                                wx.reLaunch({
                                    url: './mine'
                                });
                                wx.showToast({
                                    title: '文章删除成功'
                                });
                            }
                        }
                    })
                } else if (res.cancel) {
                    a.setData({ isShowMore: !0 });
                }
            }
        })
        
    },
    // 权限设置
    showPowerModal: function(){
        this.setData({
            isShowPower: !0,
            isShowMore: !1
        });
    },
    cancelEditPower: function (t) {
        this.setData({
            isShowPower: !1
        });
    },
    changePower: function (t) {
        var a = t.currentTarget.dataset.id;
        this.data.powerId = a;
        this.setData({
            powerId: a
        });
    },
    beforeEditPower: function(){
        var authority = this.data.powerId, a_id = this.data.a_id;
        this.setData({ isShowPower: !1 });
        wx.request({
            url: api.globalData.Api + '/articleRule',
            method: 'POST',
            data: {
                a_id: a_id,
                authority: authority
            },
            header: api.header,
            success(res){
                if(res.data.status == 1){
                    wx.showToast({
                        title: '权限修改成功'
                    });
                }
            }
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        // if (this.data.musicShow == true) {
        //     this.data.innerAudioContext.play();
        // }
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {
        this.data.innerAudioContext.pause();
    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {
        this.data.innerAudioContext.pause();
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },

    // 音乐点击
    palyAudio: function () {
        if (this.data.isPlay) {
            this.data.innerAudioContext.pause()
            this.setData({
                isPlay: !1
            })
        } else {
            this.data.innerAudioContext.play()
            this.setData({
                isPlay: 1,
            })
        }
    },
    // 回到首页
    goHome: function () {
        wx.switchTab({
            url: "../discover/discover"
        });
    },
})